/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.click.app;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

/**
 *
 * @author ronald
 */
public class TestAll {
    public static void main(String arg[]){
        List<String> names = new ArrayList<String>();
        names.add("tipo");
        names.add("color");
        
        List<String> values = new ArrayList<String>();
        values.add("tela");
        values.add("rojo");

        List<String> opNames = new ArrayList<String>();
        opNames.add("=");
        opNames.add("=");
        List<String> opValues = new ArrayList<String>();
        opValues.add("!=");
        opValues.add("!=");

        List<String> joinsFields = new ArrayList<String>();
        joinsFields.add("AND");

        System.out.println(generateFilter( names, opNames
                                       , values, opValues
                                       , "distinctive.name", "distinctive.value", joinsFields ));


    }
    public static Long[] getValueFromLabel(List<String> list){
        Long []values = new Long[list.size()];
        int i=0;
        for(String l : list){
            String value[] = l.split("]");
            String numString = value[0].substring(1,value[0].length());
            values[i] = new Long(numString);
            i++;
        }
        return values;
    }
    public static String generateFilter( List<String> names, List<String> operatorNames
                                       , List<String> values, List<String> operatorValues
                                       , String name, String value, List<String> joinsFields ){
        StringBuffer result = new StringBuffer();

        for (Iterator<String> itNames = names.iterator() , itOpNames = operatorNames.iterator()
            , itValues = values.iterator() , itOpValues = operatorValues.iterator()
            , itJoinsField = joinsFields.iterator() ; itNames.hasNext();) {
            String nameX = itNames.next();
            String opNameX = itOpNames.next();
            String valueX = itValues.next();
            String opValueX = itOpValues.next();

            result.append(" ( ");
            result.append(name);
            result.append(opNameX);
            result.append("'"+nameX+"'");
            result.append(" AND ");
            result.append(value);
            result.append(opValueX);
            result.append("'"+valueX+"'");
            result.append(" ) ");

            if(itNames.hasNext()){
                String joinField = itJoinsField.next();
                result.append(" "+joinField+" ");
            }
        }

        return result.toString();
    }
}